<template>
  <div class="table-page-search-wrapper">
    <a-card>
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :md="6" :sm="12">
            <a-form-item label="学号">
              <a-input v-model="queryParam.xh"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item label="姓名">
              <a-input v-model="queryParam.xm"/>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
            <a-col :md="6" :sm="12">
              <a-form-item label="学生类别">
                <a-select allowClear v-model="queryParam.xslbm">
                  <a-select-option v-for="i in TYPE0075" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="培养单位">
                <a-select allowClear v-model="queryParam.ssyxm" @change="yxChange" showSearch :filterOption="filterOption">
                  <a-select-option v-for="i in selectMenu.yxList" :key="i.id" :value="i.dwh">{{ i.dwh }} {{ i.dwmc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="专业">
                <a-select v-model="queryParam.sszym" showSearch :filterOption="filterOption">
                  <a-select-option v-for="(i,index) in selectMenu.zyList" :key="index" :value="i.zyh">{{ i.zyh}} {{ i.zymc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="年级">
                <a-select allowClear v-model="queryParam.sznj">
                  <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="8" :sm="12">
            <span class="table-page-search-submitButtons" >
            <a-button type="primary" @click="$refs.table.refresh(true)" style="margin:0 10px">查询</a-button>
            <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <a-card :bordered="false" style="margin-top: 10px">
      <s-table
        v-if="initDone"
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        :alert="{show: true}"
        :scroll="{ x: 1400 }"
        :pageSize="parameter.pageSize"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 + (parameter.pageNo - 1) * parameter.pageSize }}
        </span>
        <template slot="operation" slot-scope="a,b">
          <a @click="showCheck(b)">审核</a>
        </template>
      </s-table>
    </a-card>
    <check-modal ref="check" :visible="checkVisible" @cancel="checkVisible = false" @refresh="$refs.table.refresh(false)"/>
  </div>
</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'
import checkModal from './checkModal'

export default {
  data () {
    return {
      advanced: true,
      queryParam: {},
      columns: [
        {
          title: '序号',
          width: '80px',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '学号',
          dataIndex: 'xh'
        },
        {
          title: '姓名',
          dataIndex: 'xm'
        },
        {
          title: '性别',
          width: '80px',
          dataIndex: 'xbmc'
        },
        {
          title: '年级',
          width: '100px',
          dataIndex: 'sznjmc'
        },
        {
          title: '培养单位',
          dataIndex: 'dwmc'
        },
        {
          title: '专业',
          dataIndex: 'zymc'
        },
        {
          title: '学生类别',
          dataIndex: 'xslbmc'
        },
        {
          title: '导师',
          dataIndex: 'dsxm'
        },
        {
          title: '操作',
          dataIndex: 'operation',
          width: '120px',
          scopedSlots: { customRender: 'operation' },
          fixed: 'right'
        }
      ],
      parameter: {
        pageNo: 1,
        pageSize: 10
      },
      loadData: parameter => {
        this.parameter = parameter
        parameter.pageNum = parameter.pageNo
        let params = Object.assign(this.queryParam, parameter)
        return this.$api.cultivate.planCheckList(params).then(res => {
          return {
            data: res.data.rows,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      selectMenu: {},
      checkVisible: false,
      confirmLoading: false,
      initDone: false
    }
  },
  components: {STable, checkModal},
  computed: {
    ...mapState({
      TYPE0126: state => state.app['TYPE0126'],
      TYPE0075: state => state.app['TYPE0075']
    })
  },
  created () {
    this.$store.dispatch('app/sysInfo', true).then(data => {
      if ( +new Date() > +data.pyjhshjssj  ||  +new Date() < +data.pyjhshkssj) {
        this.$confirm({
          title: '审核时间已过，请联系管理员',
          centered: true,
          okText: '确认',
          cancelText: '返回',
          onOk: () => {
            this.$router.back()
          },
          onCancel: () => {
            this.$router.back()
          }
        })
      }
    })
    this.$store.dispatch('app/setDictionary', 'TYPE0075')
    this.$store.dispatch('app/setDictionary', 'TYPE0126')
    this.initSelectMenu()
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll(),
        this.$store.dispatch('app/sysInfo')
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yxList: res[0].data
        }
        this.$set(this.queryParam, 'sznj', res[1].currentGrade)
        this.initDone = true
      })
    },
    filterOption (value, yx) {
      return yx.componentOptions.children[0].text.indexOf(value) !== -1
    },
    yxChange (code) {
      this.$set(this.queryParam, 'sszym', '')
      if (code) {
        this.$api.base.majorAll({lsdwh: code}).then(res => {
          this.$set(this.selectMenu, 'zyList', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'zyList', [])
      }
    },
    showCheck (t) {
      // this.$router.push(`/cultivate/scheme/detail/${t.id}`)
      // this.$api.cultivate.planDetail(t.id)
      this.checkVisible = true
      this.$refs.check.getInfo(t.id)
    }
  }
}
</script>

<style>

</style>
